package com.ruoyi.web.controller.littleRedBook;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.Project;
import com.ruoyi.littleRedBook.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 项目表 前端控制器
 * </p>
 *
 * @author
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/api/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 新增项目
     */
    @PostMapping
    public AjaxResult add(@RequestBody Project project) {
        return AjaxResult.success(projectService.save(project));
    }

    /**
     * 修改项目
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Project project) {
        return AjaxResult.success(projectService.updateById(project));
    }

    /**
     * 删除项目
     */
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds) {
        return AjaxResult.success(projectService.removeByIds(Arrays.asList(projectIds)));
    }

    /**
     * 查询项目详情
     */
    @GetMapping("/{projectId}")
    public AjaxResult getInfo(@PathVariable Long projectId) {
        return AjaxResult.success(projectService.getById(projectId));
    }

    /**
     * 查询项目列表
     */
    @GetMapping
    public AjaxResult list() {
        return AjaxResult.success(projectService.list());
    }
}
